/**
 * Created by lxy_920912 on 16/9/5.
 */
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var jshintStyle = require('jshint-stylish');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var cssMin= require('gulp-clean-css');//压缩css
var csslint = require('gulp-csslint');//检查css 错误
var cssLintStyle = require('gulp-csslint');//css 检查错误报告样式
var htmlmin = require('gulp-htmlmin');


var imgMin = require('gulp-imagemin');
var watch = require('gulp-watch');
//var clean = require('gulp-clean');s
var del = require('del')
gulp.task('default',['uglify','cssMin','htmlMin','copyJs'],function () {
   console.log('compress finished!!!');

});
/*压缩js文件
* */
gulp.task('uglify',['jshint'],function () {
   gulp.src('js/*.js')
       .pipe(uglify())
       .pipe(concat('all.min.js'))
       .pipe(gulp.dest('build/js'));
});

/*检查js文件错误
* */
gulp.task('jshint',function () {
   gulp.src('js/*.js')
       .pipe(jshint())
       .pipe(jshint.reporter(jshintStyle))
});

gulp.task('concat',function () {
   gulp.src('build/*.js')
       .pipe(concat('all.js'))
       .pipe(rename({suffix:'.min'}))
       .pipe(gulp.dest('jquery'));
});

/*清除文件
* */
gulp.task('clean',function () {
   del('build/*.js');
   del('build')
});
gulp.task('cssMin',['cssLint'],function () {
   gulp.src('css/index.css')
       .pipe(cssMin({}))
       .pipe(rename({suffix:'.min'}))
       .pipe(gulp.dest('build/css'));
});

csslint.addFormatter('csslint-stylish');
gulp.task('cssLint',function () {
   gulp.src('css/index.css')
       .pipe(csslint())
       .pipe(csslint.formatter('stylish'));
});

gulp.task('imgMin',function(){//图片压缩
   gulp.src('pic/*.jpg')
       .pipe(imgMin())
       .pipe(gulp.dest('pic-min'));
  //return del('pic');
});
gulp.task('watch',function () {
   watch('build/*.js',['concat']);
})
gulp.task('htmlMin',function () {
   gulp.src('index.html')
       .pipe(htmlmin({collapseWhitespace:true}))
       .pipe(rename('index.min.html'))
       .pipe(gulp.dest('build'))
});
gulp.task('copyJs',function () {
   gulp.src('jquery/*.js')
       .pipe(gulp.dest('build/js'));
})
